package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.domain.UserInfoEs;
import cn.wolfcode.wolf2w.business.repository.UserInfoEsRepository;
import cn.wolfcode.wolf2w.business.service.IUserInfoEsService;
import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.member.api.RemoteUserInfoService;
import cn.wolfcode.wolf2w.member.api.domain.UserInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserInfoEsServiceImpl implements IUserInfoEsService {
    @Autowired
    private RemoteUserInfoService remoteUserInfoService;

    @Autowired
    private UserInfoEsRepository userInfoEsRepository;



    @Override
    public void initUserInfoEs() {
        //返回所有攻略的数组
        List<UserInfo> list= remoteUserInfoService.list(SecurityConstants.INNER).getData();
        List<UserInfoEs> esList = new ArrayList<>();

        for (UserInfo UserInfo : list) {
            UserInfoEs es = new UserInfoEs();
            //同名属性用拷贝,第一个参数：源头，第二个：目的
            BeanUtils.copyProperties(UserInfo,es);
            esList.add(es);
        }
        userInfoEsRepository.saveAll(esList);
    }
}